#/bin/bash
set -e

# This script file automatically sets up and tears down the automake/autoconf
# directroy.  We have a special script so that the repository stays 
# sqeaky clean and does not have all the automake files checked in.
# Just after checking out the subdirectroy from the repository, call:
#
# ./genconf.sh
# 
# This will setup the autoconf/automake environment.  You should then 
# be able to call './configure' then 'make'.
# 
# As with all autoconf files, it is a good idea to run './configure --help'
# to figure out what things can/should be configured.
# 
# This script also takes the -u option, which is to UNinstall the autoconf
# generated files.  This is most useful just before checking in to the 
# CVS repository.  

if [ "$1" = "-u" ]; then
   pushd $(dirname $(readlink -f $0))
   # Uninstall 
   if [ -e Makefile ]; then
      make maintainer-clean
   fi 
   rm -rf  3rdparty/install
   rm -rf  3rdparty/build
   find  -name "*~" -exec rm -f {} \;
   rm -f Makefile.in configure aclocal.m4
   rm -rf config autom4te.cache build m4
   rm -rf .deps/ 2>/dev/null
   popd
   exit 0
fi

if [ "$1" = "" ]; then
  PACKAGE_VERSION=1.0.`date +%m%d%H_%M%S`
else
  PACKAGE_VERSION=$1
fi

cp configure.ac configure.ac.new
sed 's/AC_INIT(\[\(.*\)\],\[.*\])/AC_INIT(\[\1\],\['$PACKAGE_VERSION'\])/' < configure.ac.new > configure.ac
rm configure.ac.new

echo Setting up build environment... Please wait...

libtoolize
aclocal
autoconf
automake --add-missing

echo "Now, run './configure'.  After that completes, run 'make'."

